package ini_reader

import (
	"os"
	"time"
)

// interface Listener
type Listener interface {
	Listen(string) error
}

// to implemente the interface Listener 
type FileListener struct {
}

// Listen implemented by FileListener
func (fl FileListener) Listen(filePath string) error {
	originStat, err := os.Stat(filePath)
	originSSize := originStat.Size()
	originSModTime := originStat.ModTime()
	if err != nil {
		return ErrGetStat
	}

	for {
		stat, err := os.Stat(filePath)
		if err != nil {
			return ErrGetStat
		}

		// file change detected
		if stat.Size() != originSSize || stat.ModTime() != originSModTime {
			break
		}
		time.Sleep(1 * time.Second)
	}
	return nil
}